/*
 * @Descripttion:
 * @version:
 * @Author: ChenXiang
 * @Date: 2021-08-01 16:54:44
 * @LastEditors: ChenXiang
 * @LastEditTime: 2021-08-07 21:43:23
 */
import React from "react";
import { RouterContext } from "./Context";
import matchPath from "./matchPath";

export default class Route extends React.Component {
  render() {
    return (
      <RouterContext.Consumer>
        {(context) => {
          const location = context.location;

          const { children, component, render, path } = this.props;
          // const match = window.location.pathname === path;

          // const match = location?.location?.pathname === path;
          const match = path
            ? matchPath(location.pathname, this.props)
            : context.match;
          console.log("match", match);
          console.log("location", location);
          const props = {
            ...context,
            match,
          };
          console.log("props", props);
          return match ? React.createElement(component, props) : null;
        }}
      </RouterContext.Consumer>
    );
  }
}
